package mo.golden;

public class L03_01 {

    private int stackSize;
    private int[] arr;
    private int[] lens;

    public L03_01(int stackSize) {
        this.arr = new int[3*stackSize];
        this.stackSize = stackSize;
        this.lens = new int[3];
        for (int i = 0; i < 3; i++) {
            lens[i] = i * stackSize;
        }
    }

    public void push(int stackNum, int value) {
        boolean canPush = lens[stackNum] < (stackNum + 1) * stackSize;
        if (!canPush) {
            return;
        }
        arr[lens[stackNum]] = value;
        lens[stackNum]++;
    }

    public int pop(int stackNum) {
        if (lens[stackNum] == stackNum * stackSize) {
            return -1;
        }
        lens[stackNum]--;
        return arr[lens[stackNum]];
    }

    public int peek(int stackNum) {
        if (lens[stackNum] == stackNum * stackSize) {
            return -1;
        }
        return arr[lens[stackNum]-1];
    }

    public boolean isEmpty(int stackNum) {
        return lens[stackNum] == stackNum * stackSize;
    }

    public static void main(String[] args) {
        L03_01 test = new L03_01(1);
        test.push(0, 1);
        test.push(0, 2);
        System.out.println(test.pop(0));
    }

}
